package com.fortune.controller;

import com.fortune.base.BaseAPIExcution;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.PMenuExcution;
import com.fortune.entity.PUserInfo;
import com.fortune.enums.PMenuEnum;
import com.fortune.service.PPomissionService;
import com.fortune.vo.pPermission.PMenu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Api(value = "pMenu", description = "平台菜单", tags = {"平台菜单相关"})
@RestController
@RequestMapping("pMenu")
public class PMenuController {
	@Autowired
	private PPomissionService pPomissionService;

	@ApiOperation(value = "获取菜单列表", nickname = "pMenu", notes = "", tags={ "@石匡" })
	@GetMapping(value = "list", produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<List<PMenu>> listMenus(HttpServletRequest request){
		HttpSession session = request.getSession();
		PUserInfo pUserInfo = (PUserInfo) session.getAttribute(Constants.SESSION_P_USER);
		String positionId = pUserInfo.getPpositionId();
		List<PMenu> menus = pPomissionService.listMenusByPositionId(positionId);
		return new PMenuExcution<List<PMenu>>(menus,PMenuEnum.FIND_SUCCESS);
	}
}
